package com.example.smartcity.ui.Adapter;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.example.smartcity.R;
import com.example.smartcity.ui.Bean.DelivaryMessageBean;

import java.util.List;

public class SelfDivListViewAdapter extends ArrayAdapter<DelivaryMessageBean> {
    int resource;
    public SelfDivListViewAdapter(@NonNull Context context, int resource, @NonNull List<DelivaryMessageBean> objects) {
        super(context, resource, objects);
        this.resource =resource;
    }

    @NonNull
    @Override
    public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
        DelivaryMessageBean bean = getItem(position);
        View view ;
        MyViewHolder myViewHolder;
        if (convertView==null){
            view = LayoutInflater.from(parent.getContext()).inflate(resource,parent,false);
            myViewHolder = new MyViewHolder();
            myViewHolder.TVGetCode1 = view.findViewById(R.id.TV_getCode1);
            myViewHolder.TVGetPosition = view.findViewById(R.id.TV_getPosition);
            myViewHolder.TVGetTime1 = view.findViewById(R.id.TV_getTime1);
            myViewHolder.codePhoto = view.findViewById(R.id.IV_codePhoto);
            view.setTag(myViewHolder);
        }else{
            view = convertView;
            myViewHolder = (MyViewHolder) view.getTag();
        }
        myViewHolder.codePhoto.setImageResource(R.drawable.codephone);
        myViewHolder.TVGetTime1.setText(bean.getTime());
        myViewHolder.TVGetPosition.setText(bean.getAddress());
        Log.d("TAG", "getView: "+bean.getAddress());
        myViewHolder.TVGetCode1.setText(bean.getCode());
        return view;
    }
    static class MyViewHolder{
        private ImageView codePhoto;
        private TextView TVGetCode1;
        private TextView TVGetPosition;
        private TextView TVGetTime1;
    }
}
